<include file="Public:header" />
<include file="Public:leftside" />
<style type="text/css">
	.modal {
	    height: 600px;
	   
	}
	.modal-infp-style {
		width: 90%;
		margin: 10px auto;
	}
	
	.modal-infp-style table {
		width: 100%;
	}
	
	.modal-infp-style table tr td {
		border: 1px solid #e6e6e6;
		padding: 8px;
	}
	
	a:hover {
		cursor: pointer;
	}

	.pagination a{display: block;float: left;border-bottom-left-radius: 3px;border-top-left-radius: 3px;padding: 5px 10px;font-size: 12px;font-weight: 500;border-radius: 2px;}
	.pagination span{display: block;float: left;border-bottom-left-radius: 3px;border-top-left-radius: 3px;background-color: #fafafa;border: 1px solid #dddddd;padding: 5px 10px;font-size: 12px;font-weight: 500;border-radius: 2px;}

</style>
<div class="main-content">
	<div class="breadcrumbs breadcrumbs-fixed" id="breadcrumbs">
		<ul class="breadcrumb">
			<li> <i class="icon-home home-icon"></i>
				<a href="/">首页</a>
			</li>
			<li class="active">会员管理</li>
		</ul>
	</div>
	<section class="scrollable wrapper">
		<!--<div class="row panel-body" style="padding-top:0px;">
			<a href="http://test.niushop.com/index.php/platform/member/memberlist.html" class="btn btn-sm btn-primary">会员列表</a>
			<a href="http://test.niushop.com/index.php/platform/member/memberlevellist.html" class="btn btn-sm btn-default">会员等级</a>
			<a href="http://test.niushop.com/index.php/platform/member/usercommissionwithdrawlist.html" class="btn btn-sm btn-default">会员提现</a>
			<a href="http://test.niushop.com/index.php/platform/member/pointlist.html" class="btn btn-sm btn-default">积分管理</a>
			<a href="http://test.niushop.com/index.php/platform/member/accountlist.html" class="btn btn-sm btn-default">余额管理</a>
			<a href="http://test.niushop.com/index.php/platform/member/weixinfanslist.html" class="btn btn-sm btn-default">粉丝列表</a>
		</div>-->
		<!-- 操作提示  start -->
		<!-- 操作提示  end -->
		<form action="__CONTROLLER__/index/" method="get">
		<div class="row padder-v">
			<div class="col-sm-9" style="width:65%;">
				<a href="javascript:;" class="btn btn-sm btn-primary" onclick="add_user();"><i class="fa fa-plus"></i> 添加会员 </a>
			</div>
			<div class="col-sm-2">
				<input type="text" name="phone" value="<?=$_GET['phone']?>" class="form-control input-sm" placeholder="请输入用户手机号"/>
			</div>
			<div class="col-sm-2" >
				<button class="btn btn-sm btn-default" type="submit" >搜索</button>
				<a href="{:U('Users/index')}" class="btn btn btn-info btn-sm" >清空</a>
			</div>
		</div>
		</form>
		<section class="panel panel-default">
			<div class="table-responsive">
				<table class="table table-striped b-t b-light text-sm">
					<thead>
						<tr>

							<th>会员</th>
							<th class="center">会员等级</th>

							<th class="center">账户余额</th>
							<th class="center">注册&amp;登录</th>
							<th class="center">状态</th>
							<th class="center">操作</th>
						</tr>
					</thead>
					<tbody id="list">
						<foreach name="users_list" item="v">
							<tr align="center">
								<td align="left">
									<img src="{$v.user_pic}" class="head-portrait" style="float: left;">
									<span style="float: left;margin-left: 6px;line-height: 20px;">
										昵称 : {$v.username}<br>
										手机 : {$v.phone}
									</span>
								</td>
								<td class="tal">普通会员</td>

								<td class="tal">¥{$v.money}</td>
								<php>
									if($v['login_time']==''){ $v['login_time']=date('Y-m-d H:i:s',$v['addtime']); }
								</php>
								<td class="tal">注册时间 : {:date('Y-m-d H:i:s',$v['addtime'])}<br>最后登录 :{$v['login_time']}</td>
								<td style="color:green;">
									<eq name="v.ishidden" value="0">禁用</eq>
									<eq name="v.ishidden" value="1">启用</eq>
								</td>
								<td>
									<notempty name="v['phone']">
										<php>$count=tj_count_user($v['id']);</php>
										<a href="{:U('users/angel',array('id'=>$v['id']))}">天使代言人</a><br>
										<a href="{:U('users/tj_user',array('id'=>$v['id']))}">推荐({$count})</a><br>
										<a href="{:U('users/accountdetail',array('id'=>$v['id']))}">余额明细</a><br>
										<a onclick="recharge_balance({$v.id},{$v.money})">余额调整</a><br>
										<a onclick="modify_password({$v.id})">重置密码</a><br>
										<a onclick="modify_user({$v.id})">修改</a>&nbsp;
									</notempty>
									<empty name="v['phone']">
									  第三方用户<br/>不支持修改
								    </empty>

							</tr>
						</foreach>
					</tbody>
				</table>
			</div>

			<footer class="panel-footer">
				<div class="row" id="page">
				<div class="col-sm-2 text-center">
						<small class="text-muted inline m-tb-8">总计 <span id="total_count_num">{$count}</span>个记录</small>
					</div>
					<div class="col-sm-5 text-right text-center-xs">
						<ul class="pagination pagination-sm m-t-none m-b-none">
							{$page}
						</ul>
					</div>
				</div>
			</footer>

		</section>

		<script type="text/javascript">
			//余额充值
			function recharge_balance(uid, balance) {
				$("#recharge_balance").modal("show");
				$("#balance_id").val(uid);
				$("#current_balance").text(balance);
			}
			//充值
			function addAccount(type) {
				
				var id = $("#balance_id").val();
				var num = $("#balance").val();
				var current_balance = $("#current_balance").text();
				var balance = (parseInt(current_balance) + parseInt(num));
				if(num == '') {
					layer.msg('余额不能为空！')
					return false;
				}
				var text = $("#remark_balance").val();
				if(parseInt(balance) < 0) {
					layer.msg('余额不能为负数！')
					return false;
				}
				
				$.ajax({
					type: "post",
					url: "{:U('users/addmemberaccount')}",
					data: {
						"id": id,
						"type": type,
						"num": num,
						"text": text
					},
					success: function(data) {
						if(data['code'] == 0) {
							layer.msg('无数据更新！')
						} 
						if(data['code'] == 1) {
							layer.msg('修改成功！');
							setTimeout("location.reload()",1000);
						} 
					}
				});
			}
			//修改会员弹出
			function modify_user(uid) {
				var id = parseInt(uid);
				$("#modify_user").modal("show");
				$.ajax({
					type: "post",
					url: "{:U('users/getmemberdetail')}",
					data: {
						'uid': id,
					},
					success: function(data) {
						$("#modify_uid").val(data.id);
						$("#modify_username").text(data.phone);
						$("#modify_nickname").val(data.username);
						$("#modify_member_level").find("option[value=" + data.member_level + "]").attr("selected", true);
						$("#sex").find("input[value=" + data.sex + "]").attr("checked", true);
						$("#status").find("input[value=" + data.ishidden + "]").attr("checked", true);
						
					}
				});
			}
			
			function modifyUser(){
				var uid = $("#modify_uid").val();
				var nickname = $("#modify_nickname").val();
				var level_name = $("#modify_member_level").val();
				var sex = $("input[name='sex']:checked").val();
				var status = $("input[name='status']:checked").val();
				
				$.ajax({
					type : "post",
					url : "{:U('users/updatemember')}",
					data : {
						'id':uid,
						'username' : nickname,
						'member_level' : level_name,
						'sex' : sex,
						'ishidden' : status
					},
					success : function(data) {
						if(data['code'] == 0) {
							layer.msg('无数据更新！')
						} 
						if(data['code'] == 1) {
							layer.msg('修改成功！');
							setTimeout("location.reload()",1000);
						} 
					}
				});
			}

			/**
			重置密码弹出
			*/
			function modify_password(uid) {
				$("#modify_password").modal("show");
				$("#modify_userid").val(uid);
			}
			/**
			修改密码提交
			*/
			function modifypassword() {
				var uid = $("#modify_userid").val();
				var password = $("#modify_passwords").val();
				if(password == null || password.length < 6) {
					layer.msg('密码必须不小于6位！')
					return false;
				}
				$.ajax({
					type: "post",
					url: "{:U('users/updatememberpassword')}",
					data: {
						'uid': uid,
						'user_password': password
					},
					success: function(data) {
						if(data['code'] == 0) {
							layer.msg('无数据更新！')
						} 
						if(data['code'] == 1) {
							layer.msg('修改成功！');
							setTimeout("location.reload()",1000);
						} 
					}
				});
			}
			//添加会员弹出
			function add_user() {
				$("#add_user").modal("show");
			}
			//添加会员
			function addUser() {
				var username = $("#username").val();
				var password = $("#password").val();
				var nickname = $("#nickname").val();
				var level_name = $("#member_level").val();
				var sex = $("input[name='sex']:checked").val();
				var status = $("input[name='status']:checked").val();

				if(username == '') {
					layer.msg('手机不能为空')
					return;
				}

				if(!checkUserName(username)) {
					layer.msg('用户已存在')
					return;
				}
				//检测输入的会员用户名是否已经存在
				$("#username").blur(function() {
					var username = $(this).val();
					$(this).css("border", "1px solid #ccc");
					$("#usernameyz").css("color", "black").text("");
					$("#isset_username").attr("value", "不存在");
					if(username === $("#modify_username_hidden").val()) {
						return;
					}
					checkUserName(username);
				});

				function checkUserName(username) {
					var flag = true;
					$.ajax({
						type: "GET",
						url: "{:U('users/check_username')}",
						async: false,
						data: {
							"username": username
						},
						success: function(data) {
							if(data.code==1) {
								flag = false;
								$("#username").css("border", "1px solid red");
								$("#usernameyz").css("color", "red").text("用户名已存在");
								$("#isset_username").attr("value", "存在");
							}
						}
					});
					return flag;
				}
				if(password == null || password.length < 6) {
					layer.msg('密码必须不小于6位！')
					return;
				}
				if(username.length > 0) {
					if(!(/^1(3|4|5|7|8)\d{9}$/.test(username))) {
						layer.msg('手机号码有误，请重填！')
						return;
					}
				}
				
				$.ajax({
					type: "post",
					url: "{:U('users/addmember')}",
					data: {
						'username': username,
						'password': password,
						'nickname':nickname,
						'level_name': level_name,
						'sex': sex,
						'status': status
					},
					success: function(data) {
						if(data['code'] == 0) {
							layer.msg('用户添加失败！')
						} 
						if(data['code'] == 1) {
							layer.msg('用户添加成功！');
							setTimeout("location.reload()",1000);
						} 
						if(data['code'] == 2) {
							layer.msg('该用户已存在！')
						} 
					}
				});

			}
		</script>
		<!-- 余额调整 -->
		<div class="modal" id="recharge_balance" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
						<h4 class="modal-title" id="myModalLabel">调整余额</h4>
					</div>
					<div class="modal-body">
						<div class="modal-infp-style">
							<table>
								<tbody>
									<tr>
										<td>当前余额</td>
										<td colspan="3" id="current_balance"></td>
									</tr>
									<tr>
										<td>调整金额</td>
										<td colspan="3" id="time"><input type="number" id="balance" class="balance">增加或减少</td>
									</tr>
									<tr>
										<td>备注</td>
										<td colspan="3" id="time"><textarea id="remark_balance"></textarea></td>
									</tr>
								</tbody>
							</table>
						</div>
					</div>

					<div class="modal-footer">
						<input type="hidden" id="balance_id">
						<button class="btn btn-info" onclick="addAccount(2)" id="butSubmit" data-dismiss="modal" aria-hidden="true" style="display:inline-block;">保存</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					</div>
				</div>
			</div>

		</div>

		<!-- 添加会员 -->
		<div class="modal" id="add_user" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
						<h4 class="modal-title" id="myModalLabel">添加会员</h4>
					</div>
					<div class="modal-body">
						<div class="modal-infp-style" style="height:260px;overflow:auto;">
							<table class="modal-tab">
								<tbody>
									<tr>
										<td style="width:20%;"><span class="required">*</span>手机号码</td>
										<td colspan="3">
											<input type="text" id="username">
											<span id="usernameyz"></span>
										
										</td>
									</tr>
									<tr>
										<td><span class="required">*</span>登录密码</td>
										<td colspan="3"><input type="password" id="password" class="balance"></td>
									</tr>
									<tr>
										<td style="width:22%;">昵称</td>
										<td colspan="3">
											<input type="text" id="nickname">
										</td>
									</tr>
									<tr>
										<td>会员等级</td>
										<td colspan="3">
											<p>
												<select id="member_level">
													<option value="1">普通会员</option>
												</select>
											</p>
										</td>
									</tr>
									<tr>
										<td>性别</td>
										<td><label><input type="radio" checked="checked" name="sex" value="1">男&nbsp;&nbsp;</label><label><input name="sex" type="radio" value="2">女&nbsp;&nbsp;</label><label><input name="sex" type="radio" value="0">保密</label></td>
									</tr>
									<tr>
										<td>账户状态</td>
										<td><label><input type="radio" checked="checked" name="status" value="1">正常&nbsp;&nbsp;</label>
											<label><input name="status" type="radio" value="0">锁定</label></td>
									</tr>
								</tbody>
							</table>
						</div>
					</div>

					<div class="modal-footer">
						<button class="btn btn-info" onclick="addUser()" id="butSubmit" style="display:inline-block;">保存</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					</div>
				</div>
			</div>

		</div>
		<input type="hidden" id="modify_uid">

		<!-- 修改会员 -->
		<div class="modal" id="modify_user" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
						<h4 class="modal-title" id="myModalLabel">编辑会员</h4>
					</div>
					<div class="modal-body">
						<div class="modal-infp-style" style="height:260px;overflow:auto;">
							<table class="modal-tab">
								<tbody>
									<tr>
										<td style="width:20%"><span class="required">*</span>用户名</td>
										<td colspan="3">
											<span id="modify_username"></span>
										</td>
									</tr>
									<tr>
										<td style="width:20%">昵称</td>
										<td colspan="3"><input type="text" id="modify_nickname"></td>
									</tr>
									<tr>
										<td>会员等级</td>
										<td colspan="3">
											<p>
												<select id="modify_member_level">
													<option value="1">普通会员</option>
												</select>
											</p>
										</td>
									</tr>
									<tr>
										<td>性别</td>
										<td id="sex"><label><input type="radio" name="sex" value="1">男&nbsp;&nbsp;</label><label><input name="sex" type="radio" value="2">女&nbsp;&nbsp;</label><label><input name="sex" type="radio" value="0">保密</label></td>
									</tr>
									<tr>
										<td>账户状态</td>
										<td id="status"><label><input type="radio" name="status" value="1">正常&nbsp;&nbsp;</label><label><input name="status" type="radio" value="0">锁定</label></td>
									</tr>
								</tbody>
							</table>
						</div>
					</div>

					<div class="modal-footer">
						<input type="hidden" id="modify_username_hidden">
						<button class="btn btn-info" onclick="modifyUser()" id="butSubmit" style="display:inline-block;">保存</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					</div>
				</div>
			</div>

		</div>
		<!-- 修改会员 -->
		<div class="modal" id="modify_password" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
						<h4 class="modal-title" id="myModalLabel">重置密码</h4>
					</div>
					<div class="modal-body">
						<div class="modal-infp-style">
							<table class="modal-tab">
								<tbody>
									<tr>
										<td style="width:20%">密码</td>
										<td colspan="3"><input type="text" id="modify_passwords"></td>
									</tr>
								</tbody>
							</table>
						</div>
					</div>

					<div class="modal-footer">
						<input type="hidden" id="modify_userid">
						<button class="btn btn-info" onclick="modifypassword()" id="butSubmit" style="display:inline-block;">保存</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					</div>
				</div>
			</div>

		</div>

	</section>
</div>

<include file="Public:footer" />